﻿
using HMS.DataContract.Request;
using HMS.DataContract.Response;
using HMS.Web.Helpers;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Web;
using System.Web.Mvc;


namespace HMS.Web.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var clinicCode = ConfigurationManager.AppSettings[System.Web.HttpContext.Current.Request.Url.Host];
            var client = InitializeSchedulerClient();
            var _clinic = client.GetClinicName(clinicCode);
            Clinic clinic = new Clinic();
            clinic.Id = _clinic.Id;
            clinic.Name = _clinic.Detail;
            clinic.Code = _clinic.Code;
            clinic.Phone = _clinic.Phone;
            clinic.Address = _clinic.Address;
            clinic.LandingPageUrl = _clinic.LandingPageUrl;
            client.Close();
            //string[] urlDetails = _clinic.LandingPageUrl.Split('/');
            Session["Clinic"] = clinic;
            return View(_clinic.LandingPageUrl, clinic);
            //return View(clinic);
        }

        public SchedulerClient InitializeSchedulerClient()
        {

            var binding = new BasicHttpBinding();
            binding.SendTimeout = new TimeSpan(0, 0, 0, 0, 600000);
            binding.OpenTimeout = new TimeSpan(0, 0, 0, 0, 100000);
            binding.MaxReceivedMessageSize = 10000;
            binding.ReaderQuotas.MaxStringContentLength = 10000;
            binding.ReaderQuotas.MaxDepth = 10000;
            binding.ReaderQuotas.MaxArrayLength = 10000;
            var endpointPath = ConfigurationManager.AppSettings["SchedulerEndpointPath"];
            var endpoint = new EndpointAddress(endpointPath);
            var client = new SchedulerClient(binding, endpoint);
            return client;
        }

    }
}
